package api.thread;



import java.io.File;
import java.net.URL;

public class PackageTests {
    public static void main(String[] args) {
        //1获取类的字节码对象
        Class c = PackageTests.class;
        //2.获取包对象
        Package t = c.getPackage();
        //3.获取具体的包名
        String name = t.getName();
        //4.将包结构转换成目录结构
        String diskName = name.replace(".","/");
        System.out.println(diskName);
        //5.通过类加载器获取disk(磁盘)中的绝对路径
        URL url = ClassLoader.getSystemClassLoader().getResource(diskName);
        System.out.println(url);
        //6.通过路径获取对应的File对象
        File file = new File(url.getPath());
        //7.获取目录下的文件名
        String[] list = file.list();
        for (String str:list) {
            System.out.println(str);
        }
    }
}
